package cn.jetpiece.cloud.joss.api.accossor;

import cn.jetpiece.cloud.joss.api.accossor.model.params.CreateAccessorParam;
import cn.jetpiece.cloud.joss.api.accossor.model.params.UpdateAccessorParam;
import cn.jetpiece.cloud.joss.api.accossor.model.query.AccessorQuery;
import cn.jetpiece.cloud.joss.api.accossor.model.result.AccessorResult;
import cn.jetpiece.cloud.joss.api.constant.AccessorCache;
import cn.jetpiece.cloud.model.page.PageResult;
import cn.jetpiece.cloud.model.response.Result;
import cn.jetpiece.cloud.resource.annotation.annotation.ApiResource;
import cn.jetpiece.cloud.resource.annotation.annotation.ScanResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.validation.Valid;


/**
 * 授权接口
 *
 * @author XuJZ
 * @since 2020-09-05 15:41:52
 */
@Api(tags = "授权")
@ApiResource(name = "授权")
public interface AccessorApi {

    String API = "/oss/accessors";

    /**
     * 新增授权
     *
     * @param param 新增参数
     * @return 返回结果
     */
    @ApiOperation(value = "新增授权")
    @ScanResource(name = "新增授权", path = API, method = RequestMethod.POST)
    Result<String> add(@RequestBody @Valid CreateAccessorParam param);

    /**
     * 修改授权
     *
     * @param param 修改参数
     * @return 返回结果
     */
    @ApiOperation(value = "修改授权")
    @ScanResource(name = "修改授权",path = API, method = RequestMethod.PUT)
    Result<String> update(@RequestBody @Valid UpdateAccessorParam param);

    /**
     * 删除授权
     *
     * @param id 主键
     * @return 返回结果
     */
    @ApiOperation(value = "删除授权")
    @ScanResource(name = "删除授权", path = API +  "/{id}", method = RequestMethod.DELETE)
    Result<String> delete(@PathVariable(name = "id") String id);

    /**
     * 通过公钥查询授权信息
     *
     * @param accessKey 公钥
     * @return 返回结果
     */
    @ApiOperation(value = "查询授权信息")
    @ScanResource(name = "查询授权信息", path = API + "/action/getByAccessKey/{accessKey}", method = RequestMethod.GET)
    Result<AccessorCache> getByAccessKey(@PathVariable(name = "accessKey") String accessKey);

    /**
     * 查询授权信息
     *
     * @param id 主键
     * @return 返回结果
     */
    @ApiOperation(value = "查询授权信息")
    @ScanResource(name = "查询授权信息", path = API + "/{id}", method = RequestMethod.GET)
    Result<AccessorResult> get(@PathVariable(name = "id") String id);

    /**
     * 分页获取授权
     *
     * @param query 查询条件
     * @return 返回结果
     */
    @ApiOperation(value = "分页获取授权")
    @ScanResource(name = "分页获取授权",path = API, method = RequestMethod.GET)
    Result<PageResult<AccessorResult>> page(AccessorQuery query);

}
